package ui;

import java.awt.Color;
import java.awt.GridLayout;
import java.util.ArrayList;

import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

import draft.Player;
import draft.Team;
import draft.Player.Position;

public class TeamDescription extends JPanel{
	
	JComboBox qbbox, rbbox, wrbox, tebox, kbox, defbox;
	JLabel qblabel, rblabel, wrlabel, telabel, klabel, deflabel;
	Team team;
	
	public TeamDescription(Team team){
		setBackground(new Color(240,240,240));
		setLayout(new GridLayout(12, 1));
		this.team = team;
		qbbox = new JComboBox();
		rbbox = new JComboBox();
		wrbox = new JComboBox();
		tebox = new JComboBox();
		kbox = new JComboBox();
		defbox = new JComboBox();
		qblabel = new JLabel("QB: " + 0 + "/1");
		rblabel = new JLabel("RB: " + 0 + "/2");
		wrlabel = new JLabel("WR: " + 0 + "/2");
		telabel = new JLabel("TE: " + 0 + "/2");
		klabel = new JLabel("K: " + 0 + "/1");
		deflabel = new JLabel("DEF: " + 0 + "/1");
		add(qblabel);
		add(qbbox);
		add(rblabel);
		add(rbbox);
		add(wrlabel);
		add(wrbox);
		add(telabel);
		add(tebox);
		add(klabel);
		add(kbox);
		add(deflabel);
		add(defbox);
	}
	
	public void update(){
		ArrayList<Player> qblist = new ArrayList<Player>();
		ArrayList<Player> rblist = new ArrayList<Player>();
		ArrayList<Player> wrlist = new ArrayList<Player>();
		ArrayList<Player> telist = new ArrayList<Player>();
		ArrayList<Player> klist = new ArrayList<Player>();
		ArrayList<Player> deflist = new ArrayList<Player>();
		ArrayList<Player> players = team.getPlayers();
		for (int i = 0; i < players.size(); i++){
			Player player = players.get(i);
			Position pos = player.getPosition();
			if (pos == Position.QB){
				qblist.add(player);
			}
			if (pos == Position.RB){
				rblist.add(player);
			}
			if (pos == Position.WR){
				wrlist.add(player);
			}
			if (pos == Position.TE){
				telist.add(player);
			}
			if (pos == Position.K){
				klist.add(player);
			}
			if (pos == Position.DEF){
				deflist.add(player);
			}
		}
		qblabel.setText("QB: " + qblist.size() + "/1");
		rblabel.setText("RB: " + rblist.size() + "/2");
		wrlabel.setText("WR: " + wrlist.size() + "/2");
		telabel.setText("TE: " + telist.size() + "/2");
		klabel.setText("K: " + klist.size() + "/1");
		deflabel.setText("DEF: " + deflist.size() + "/1");
		qbbox.removeAllItems();
		rbbox.removeAllItems();
		wrbox.removeAllItems();
		tebox.removeAllItems();
		kbox.removeAllItems();
		defbox.removeAllItems();
		for (int i = 0; i < qblist.size(); i++){
			qbbox.addItem(qblist.get(i));
		}
		for (int i = 0; i < rblist.size(); i++){
			rbbox.addItem(rblist.get(i));
		}
		for (int i = 0; i < wrlist.size(); i++){
			wrbox.addItem(wrlist.get(i));
		}
		for (int i = 0; i < telist.size(); i++){
			tebox.addItem(telist.get(i));
		}
		for (int i = 0; i < klist.size(); i++){
			kbox.addItem(klist.get(i));
		}
		for (int i = 0; i < deflist.size(); i++){
			defbox.addItem(deflist.get(i));
		}
	}

}
